package com.ruoyi.project.sms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.sms.domain.SmsGrouponRules;
import com.ruoyi.db.sms.domain.query.SmsGrouponRulesQueryVo;
import com.ruoyi.project.sms.service.SmsGrouponRulesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 团购规则Controller
 *
 * @author yfy
 * @date 2020-04-21
 */
@Api(tags="sms管理：团购规则管理")
@RestController
@RequestMapping("/sms/groupon_rules")
public class SmsGrouponRulesController extends BaseController
{
    @Autowired
    private SmsGrouponRulesService smsGrouponRulesService;

    @ApiOperation("团购状态定时检测")
    public AjaxResult smsGrouponRulesUpdateStatus()
    {
        System.out.println("执行团购状态定时检测");
        SmsGrouponRules smsGrouponRules = new SmsGrouponRules();
        return AjaxResult.success(smsGrouponRulesService.smsUpdateStatus(smsGrouponRules));
    }

    @ApiOperation("查询团购规则列表")
    @PreAuthorize("@ss.hasPermi('sms:groupon_rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsGrouponRulesQueryVo smsGrouponRulesQueryVo)
    {
        startPage();
        List<SmsGrouponRules> list = smsGrouponRulesService.selectSmsGrouponRulesList(smsGrouponRulesQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出团购规则列表")
    @Log(title = "团购规则", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('sms:groupon_rules:export')")
    @GetMapping("/export")
    public AjaxResult export(SmsGrouponRulesQueryVo smsGrouponRulesQueryVo)
    {
        List<SmsGrouponRules> list = smsGrouponRulesService.selectSmsGrouponRulesList(smsGrouponRulesQueryVo);
        ExcelUtil<SmsGrouponRules> util = new ExcelUtil<SmsGrouponRules>(SmsGrouponRules.class);
        return util.exportExcel(list, "groupon_rules");
    }

    @ApiOperation("获取团购规则详细信息")
    @Log(title = "团购规则", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('sms:groupon_rules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsGrouponRulesService.selectSmsGrouponRulesById(id));
    }

    @ApiOperation("新增团购规则")
    @Log(title = "团购规则", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('sms:groupon_rules:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SmsGrouponRules smsGrouponRules)
    {
        return toAjax(smsGrouponRulesService.insertSmsGrouponRules(smsGrouponRules));
    }

    @ApiOperation("修改团购规则")
    @Log(title = "团购规则", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('sms:groupon_rules:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SmsGrouponRules smsGrouponRules)
    {
        return toAjax(smsGrouponRulesService.updateSmsGrouponRules(smsGrouponRules));
    }

    @ApiOperation("删除团购规则")
    @Log(title = "团购规则", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('sms:groupon_rules:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsGrouponRulesService.deleteSmsGrouponRulesByIds(ids));
    }
}
